class Solution
{
public:
    vector<int> ans;
    vector<int> rightSideView(TreeNode* root)
    {
        dfs(root, 1);
        return ans;
    }
private:
    void dfs(TreeNode* root, int i)
    {
        if (root == NULL) return;

        if (ans.size() < i)
            ans.push_back(root->val);

        dfs(root->right, i + 1);
        dfs(root->left, i + 1);
    }
};